home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / MISC / BM192A.ZIP / RENDER.S < prev    next >
Encoding:
Text File  |  1996-02-23  |  21.7 KB  |  813 lines

  1. *=======================================================*
  2. *    Rendering module: latest update 23/02/96    *
  3. *=======================================================*
  4. *    Render walls & floors onto screenbuffer        *
  5. *=======================================================*
  6.  
  7. *-------------------------------------------------------*
  8. *    Texel addressing units [horizontal]        *
  9. *-------------------------------------------------------*
  10.  
  11. *-------------------------------------------------------*
  12. *    8-bit texel -> 16-bit pixel unit        *
  13. *-------------------------------------------------------*
  14.  
  15. hrun16    macro
  16.     move.l        d3,d0
  17.     move.w        d1,d0
  18.     lsr.l        #6,d0
  19.     lsr.w        #4,d0
  20.     move.b        (a1,d0.w),d6
  21.     add.l        d7,d3
  22.     move.w        (a0,d6.l*2),d0
  23.     add.w        d4,d1
  24.     move.w        d0,(a6)+
  25.     endm
  26.  
  27. *-------------------------------------------------------*
  28. *    8-bit texel -> 32-bit (double) pixel unit    *
  29. *-------------------------------------------------------*
  30.  
  31. hrun32s    macro
  32.     move.l        d7,a4
  33.     move.l        d3,d7
  34.     move.w        d1,d7
  35.     lsr.l        #6,d7
  36.     lsr.w        #4,d7
  37.     move.b        (a1,d7.w),d6
  38.     add.l        a4,d3
  39.     move.w        (a0,d6.l*2),d7
  40.     add.w        d4,d1
  41.     endm
  42.  
  43. hrun32    macro
  44.     move.l        d3,d0
  45.     move.w        d7,(a6)+
  46.     move.w        d1,d0
  47.     lsr.l        #6,d0
  48.     move.w        d7,(a6)+
  49.     lsr.w        #4,d0
  50.     move.b        (a1,d0.w),d6
  51.     add.l        a4,d3
  52.     move.w        (a0,d6.l*2),d7
  53.     add.w        d4,d1
  54.     endm
  55.  
  56. *-------------------------------------------------------*
  57. *    Texel addressing units [vertical]        *
  58. *-------------------------------------------------------*
  59.  
  60. *-------------------------------------------------------*
  61. *    8-bit texel -> 16-bit pixel unit        *
  62. *-------------------------------------------------------*
  63.  
  64. vrun16    macro
  65.     and.w        d5,d4
  66.     move.b        (a2,d4.w),d1
  67.     addx.l        d3,d4
  68.     move.w        (a5,d1.l*2),d0
  69.     adda.l        a6,a0
  70.     move.w        d0,(a0)
  71.     endm
  72.  
  73. *-------------------------------------------------------*
  74. *    8-bit texel -> 32-bit (double) pixel unit    *
  75. *-------------------------------------------------------*
  76.  
  77. vrun32    macro
  78.     and.w        d5,d4
  79.     move.b        (a2,d4.w),d1
  80.     addx.l        d3,d4
  81.     move.w        (a5,d1.l*2),d0
  82.     adda.l        a6,a0
  83.     move.w        d0,(a0)+
  84.     move.w        d0,(a0)
  85.     endm
  86.  
  87. *-------------------------------------------------------*
  88. *    Render the floors & ceilings            *
  89. *-------------------------------------------------------*
  90. render_flats:
  91. *-------------------------------------------------------*
  92.     tst.b        halfrows
  93.     bne        render_flats_2x1
  94.  
  95. *-------------------------------------------------------*
  96.     txtlong
  97. *-------------------------------------------------------*
  98. render_flats_1x1:
  99. *-------------------------------------------------------*
  100.     moveq        #rotatemap_command,d0
  101.     dspwrite.l    d0
  102. *-------------------------------------------------------*
  103.     move.l        flat_textures,.local_textures
  104.     move.l        screen,.local_screen
  105.     sf        final_flat
  106.     lea        zone_space,a3
  107.     sub.l        a4,a4
  108. *-------------------------------------------------------*
  109. *    Zone loop                    *
  110. *-------------------------------------------------------*
  111. .zone_loop:
  112. *-------------------------------------------------------*
  113.     moveq        #0,d4
  114.     move.b        (a3)+,d4            ; [zone_lines]
  115.     moveq        #0,d0
  116.     subq.w        #1,d4
  117.     bmi        .last_zone
  118. *-------------------------------------------------------*
  119.     move.b        (a3)+,d0            ; [zone_texture]
  120.     move.l        .local_textures(pc),a5
  121.     lsl.l        #8,d0
  122.     lsl.l        #4,d0
  123.     add.l        d0,a5
  124.     move.w        (a3)+,d1            ; [zone_start]
  125.     move.l        .local_screen(pc),a2
  126.     lea        (a2,d1.w*8),a2
  127. *-------------------------------------------------------*
  128. .line_loop:
  129. *-------------------------------------------------------*
  130.     move.w        (a3)+,d2            ; [line_runs]
  131.     swap        d4
  132.     subq.w        #1,d2
  133.     bmi        .null_line
  134. *-------------------------------------------------------*
  135. .run_loop:
  136. *-------------------------------------------------------*
  137.     addq.l        #flat_x2,a3
  138.     move.w        -(a3),d0
  139.     lea        DSPHost16.w,a0
  140.     move.w        d0,(a0)                ; flat_x1
  141.     lea        (a2,d0.w*2),a6
  142.     move.l        -(a3),-2(a0)            ; flat_v
  143.     swap        d2
  144.     exg.l        d5,a6
  145.     dspwaitread
  146.     move.w        (a0),d7                ; map_xi
  147.     move.w        (a0),d3                ; map_x
  148.     move.w        (a0),d4                ; map_yi
  149.     move.w        (a0),d1                ; map_y
  150. *-------------------------------------------------------*
  151. *    Avoid first run - not valid until next pass    *
  152. *-------------------------------------------------------*
  153.     tst.l        a4
  154.     beq        .invalid_run
  155. *-------------------------------------------------------*
  156. *    Render [last] flat run                *
  157. *-------------------------------------------------------*
  158.     move.l        flat_x1(a4),d6
  159.     lsl.l        #6,d3
  160.     lsl.l        #6,d7
  161.     moveq        #0,d0
  162.     move.b        flat_lz(a4),d0
  163.     move.w        d6,d2
  164.     swap        d6
  165.     sub.w        d6,d2
  166. .smod:    lea        colourtables,a0
  167.     lsl.l        #8,d0
  168.     add.l        d0,d0
  169.     add.l        d0,a0
  170.     moveq        #4-1,d0
  171.     and.w        d2,d0
  172.     asr.w        #2,d2                ; dx{loop}
  173.     move.l        d0,d6                ; dx{remainder} * -11
  174.     asl.w        #2,d6
  175.     sub.w        d6,d0
  176.     add.w        d6,d6
  177.     sub.w        d6,d0
  178. *-------------------------------------------------------*
  179. *    Flat-rendering instruction tower        *
  180. *-------------------------------------------------------*
  181.     jmp        .dx_j(pc,d0.w*2)        ; index instruction tower
  182. .dx_l:    hrun16
  183.     hrun16
  184.     hrun16
  185.     hrun16
  186. .dx_j:    dbra        d2,.dx_l
  187. *-------------------------------------------------------*
  188. .invalid_run:
  189. *-------------------------------------------------------*
  190.     move.l        a5,a1
  191.     move.l        a3,a4
  192.     addq.l        #flat_len,a3
  193. *-------------------------------------------------------*
  194.     swap        d2
  195.     dbra        d2,.run_loop
  196. *-------------------------------------------------------*
  197. .null_line:
  198. *-------------------------------------------------------*
  199.     lea        (max_xres*2)(a2),a2
  200.     swap        d4
  201.     dbra        d4,.line_loop
  202. *-------------------------------------------------------*
  203.     bra        .zone_loop
  204. *-------------------------------------------------------*
  205. .last_zone:
  206. *-------------------------------------------------------*
  207.     tst.b        final_flat
  208.     bne.s        .stop
  209.     lea        dummy_zone,a3
  210.     moveq        #0,d2
  211.     moveq        #0,d4
  212.     st        final_flat
  213.     bra        .run_loop
  214. *-------------------------------------------------------*
  215. .stop:    dspwrite.w    #-1
  216.     rts
  217.     
  218. *-------------------------------------------------------*
  219. *    Local variables                    *
  220. *-------------------------------------------------------*
  221. .local_textures:    ds.l    1
  222. .local_screen:        ds.l    1
  223. *-------------------------------------------------------*
  224.  
  225. *-------------------------------------------------------*
  226.     txtlong
  227. *-------------------------------------------------------*
  228. render_flats_2x1:
  229. *-------------------------------------------------------*
  230.     moveq        #rotatemap_command,d0
  231.     dspwrite.l    d0
  232. *-------------------------------------------------------*
  233.     move.l        flat_textures,.local_textures
  234.     move.l        screen,.local_screen
  235.     sf        final_flat
  236.     lea        zone_space,a3
  237.     sub.l        a4,a4
  238. *-------------------------------------------------------*
  239. *    Zone loop                    *
  240. *-------------------------------------------------------*
  241. .zone_loop:
  242. *-------------------------------------------------------*
  243.     moveq        #0,d4
  244.     move.b        (a3)+,d4            ; [zone_lines]
  245.     moveq        #0,d0
  246.     subq.w        #1,d4
  247.     bmi        .last_zone
  248. *-------------------------------------------------------*
  249.     move.b        (a3)+,d0            ; [zone_texture]
  250.     move.l        .local_textures(pc),a5
  251.     lsl.l        #8,d0
  252.     lsl.l        #4,d0
  253.     add.l        d0,a5
  254.     move.w        (a3)+,d1            ; [zone_start]
  255.     move.l        .local_screen(pc),a2
  256.     lea        (a2,d1.w*8),a2
  257. *-------------------------------------------------------*
  258. .line_loop:
  259. *-------------------------------------------------------*
  260.     move.w        (a3)+,d2            ; [line_runs]
  261.     swap        d4
  262.     subq.w        #1,d2
  263.     bmi        .null_line
  264. *-------------------------------------------------------*
  265. .run_loop:
  266. *-------------------------------------------------------*
  267.     addq.l        #flat_x2,a3
  268.     move.w        -(a3),d0
  269.     lea        DSPHost16.w,a0
  270.     move.w        d0,(a0)                ; flat_x1
  271.     lea        (a2,d0.w*4),a6
  272.     move.l        -(a3),-2(a0)            ; flat_v
  273.     swap        d2
  274.     exg.l        d5,a6
  275.     dspwaitread
  276.     move.w        (a0),d7                ; map_xi
  277.     move.w        (a0),d3                ; map_x
  278.     move.w        (a0),d4                ; map_yi
  279.     move.w        (a0),d1                ; map_y
  280. *-------------------------------------------------------*
  281. *    Avoid first run - not valid until next pass    *
  282. *-------------------------------------------------------*
  283.     tst.l        a4
  284.     beq        .invalid_run
  285. *-------------------------------------------------------*
  286. *    Render [last] flat run                *
  287. *-------------------------------------------------------*
  288.     move.l        flat_x1(a4),d6
  289.     lsl.l        #6,d3
  290.     lsl.l        #6,d7
  291.     moveq        #0,d0
  292.     move.b        flat_lz(a4),d0
  293.     move.w        d6,d2
  294.     swap        d6
  295.     addq.w        #1,d6
  296.     sub.w        d6,d2
  297. .smod:    lea        colourtables,a0
  298.     lsl.l        #8,d0
  299.     add.l        d0,d0
  300.     add.l        d0,a0
  301.     moveq        #4-1,d0
  302.     and.w        d2,d0
  303.     lsr.w        #2,d2                ; dx{loop}
  304.     move.l        d0,d6
  305.     lsl.w        #2,d6
  306.     sub.w        d6,d0                ; dx{remainder} * -24
  307. *-------------------------------------------------------*
  308. *    Flat-rendering instruction tower        *
  309. *-------------------------------------------------------*
  310.     hrun32s
  311.     jmp        .dx_j(pc,d0.w*8)        ; index instruction tower
  312. .dx_l:    hrun32
  313.     hrun32
  314.     hrun32
  315.     hrun32
  316. .dx_j:    dbra        d2,.dx_l
  317.     move.w        d7,(a6)+
  318.     move.w        d7,(a6)+
  319. *-------------------------------------------------------*
  320. .invalid_run:
  321. *-------------------------------------------------------*
  322.     move.l        a5,a1
  323.     move.l        a3,a4
  324.     addq.l        #flat_len,a3
  325. *-------------------------------------------------------*
  326.     swap        d2
  327.     dbra        d2,.run_loop
  328. *-------------------------------------------------------*
  329. .null_line:
  330. *-------------------------------------------------------*
  331.     lea        (max_xres*2)(a2),a2
  332.     swap        d4
  333.     dbra        d4,.line_loop
  334. *-------------------------------------------------------*
  335.     bra        .zone_loop
  336. *-------------------------------------------------------*
  337. .last_zone:
  338. *-------------------------------------------------------*
  339.     tst.b        final_flat
  340.     bne.s        .stop
  341.     lea        dummy_zone,a3
  342.     moveq        #0,d2
  343.     moveq        #0,d4
  344.     st        final_flat
  345.     bra        .run_loop
  346. *-------------------------------------------------------*
  347. .stop:    dspwrite.w    #-1
  348.     rts
  349.  
  350. *-------------------------------------------------------*
  351. *    Local variables                    *
  352. *-------------------------------------------------------*
  353. .local_textures:    ds.l    1
  354. .local_screen:        ds.l    1
  355. *-------------------------------------------------------*
  356.  
  357.     rept        0
  358.  
  359. vrun    macro
  360.     and.w        d5,d4
  361.     move.b        (a2,d4.w),d1
  362.     addx.l        d3,d4
  363.     move.w        (a5,d1.l*2),d0
  364.     adda.l        a6,a0
  365.     move.w        d0,(a0)
  366.     endm
  367.  
  368. *-------------------------------------------------------*
  369. *    Render the walls                *
  370. *-------------------------------------------------------*
  371.     txtlong
  372. *-------------------------------------------------------*
  373. render_walls:
  374. *-------------------------------------------------------*
  375.     rts
  376.     lea        wallruns,a1
  377.     moveq        #0,d6
  378.     move.w        wallruncount,d6
  379.     subq.w        #1,d6
  380.     bmi        .err
  381.     move.l        screen,a4
  382.     moveq        #0,d5
  383.     move.w        scrwidth,d5
  384.     add.l        d5,d5
  385.     move.l        d5,a6
  386.     sub.l        a6,a4
  387.  
  388.     move.w        #128-1,d5
  389.  
  390. ;    i,j1j2,z,u,dv,v
  391.     
  392.     lea        wall_texture,a3
  393. *-------------------------------------------------------*
  394. *    Wall-column horizontal loop            *    
  395. *-------------------------------------------------------*
  396. .runs:    move.w        (a1)+,d3            ; i (screen)
  397.     moveq        #0,d1
  398.     move.b        (a1)+,d1            ; j1 (screen/top)
  399.     moveq        #0,d2
  400.     move.b        (a1)+,d2            ; j2 (screen/bot)
  401.     lea        colourtables,a5
  402.     lea        (a4,d3.w*2),a0            ; address screen (i)
  403.     sub.w        d1,d2                ; dj (height)
  404.     lsl.l        #4,d1
  405.     move.l        d1,d0
  406.     move.w        (a1)+,d4            ; u (texture)
  407.     lsl.l        #2,d1
  408.     add.l        d1,d0
  409.     lsl.l        #3,d0
  410.     move.l        (a1)+,d3            ; dv[i:f] (texture)
  411.     add.l        d0,a0                ; address j (screen)
  412.     moveq        #0,d0
  413.     lea        (a3,d4.w),a2            ; address u (texture)
  414.     moveq        #0,d4
  415.     move.w        (a1)+,d4            ; v (texture)
  416.     move.b        d3,d0                ; luminance
  417.     lsl.l        #8,d0
  418.     add.l        d0,a5                ; address luminance table
  419.     asr.l        #8,d3
  420.     swap        d3
  421.     lsl.l        #8,d4
  422.     swap        d4
  423. *-------------------------------------------------------*
  424. *    Calculate tower index & interations        *
  425. *-------------------------------------------------------*
  426.     moveq        #4-1,d0
  427.     and.w        d2,d0                ; index = remainder(4)
  428.     lsr.w        #2,d2                ; loopsize / 4
  429.     neg.w        d0
  430.     add.w        d0,d0                ; index * -2
  431. *-------------------------------------------------------*
  432. *    Preload carry for cascading adder        *
  433. *-------------------------------------------------------*
  434.     move.w        d4,d1                ; store v[i]
  435.     add.l        d3,d4                ; v[i:f]=v[i:f]+dv[i:f]
  436.     move.w        d1,d4                ; restore v[i]
  437. *-------------------------------------------------------*
  438. *    Execute instruction tower            *
  439. *-------------------------------------------------------*
  440.     clr.l        d1
  441.     jmp        .dx_j(pc,d0.w*8)        ; jump -> index * -16
  442. .dx_l:    vrun
  443.     vrun
  444.     vrun
  445.     vrun
  446. .dx_j:    dbra        d2,.dx_l
  447. *-------------------------------------------------------*
  448. *    Address next wall column            *
  449. *-------------------------------------------------------*
  450.     dbra        d6,.runs
  451. .err:    rts
  452.  
  453.     endr
  454.  
  455. *-------------------------------------------------------*
  456. render_wall:
  457. *-------------------------------------------------------*
  458.     tst.b        halfrows
  459.     bne        render_wall_2x1
  460.  
  461. *-------------------------------------------------------*
  462. render_wall_1x1:
  463. *-------------------------------------------------------*
  464.     move.l        screen,a4
  465.     move.w        scrwidth,a6
  466.     add.l        a6,a6
  467.     sub.l        a6,a4
  468.     move.w        #128-1,d5
  469.     lea        wall_texture,a3
  470. *-------------------------------------------------------*
  471.     dspwaitread
  472.     move.w        (a1),d3                ; i (screen)
  473.     bmi        .dsp_done
  474. *-------------------------------------------------------*
  475. .next:    moveq        #0,d1
  476.     dspwaitread
  477.     move.w        (a1),d1                ; j1j2
  478. .smod:    lea        colourtables,a5
  479.     lea        (a4,d3.w*2),a0            ; address screen (i)
  480.     moveq        #0,d2
  481.     move.b        d1,d2                ; j2 (screen/bot)
  482.     lsr.w        #8,d1                ; j1 (screen/top)
  483.     sub.w        d1,d2                ; dj (height)
  484.     lsl.l        #4,d1
  485.     move.l        d1,d0
  486.     dspwaitread
  487.     move.w        (a1),d4                ; z
  488.     lea        (a5,d4.w*8),a5            ; address luminance table
  489.     dspwaitread
  490.     move.w        (a1),d4                ; u (texture)
  491.     lsl.l        #2,d1
  492.     add.l        d1,d0
  493.     lsl.l        #3,d0
  494.     dspwaitread
  495.     move.l        -2(a1),d3            ; dv[i:f] (texture)
  496.     add.l        d0,a0                ; address j (screen)
  497.     moveq        #0,d0
  498.     lea        (a3,d4.w),a2            ; address u (texture)
  499.     moveq        #0,d4
  500.     dspwaitread
  501.     move.w        (a1),d4                ; v (texture)
  502.     swap        d3
  503.     ext.w        d3
  504.     lsl.l        #8,d4
  505.     swap        d4
  506. *-------------------------------------------------------*
  507. *    Calculate tower index & interations        *
  508. *-------------------------------------------------------*
  509.     moveq        #4-1,d0
  510.     and.w        d2,d0                ; index = remainder(4)
  511.     lsr.w        #2,d2                ; loopsize / 4
  512.     neg.w        d0
  513.     add.w        d0,d0                ; index * -2
  514. *-------------------------------------------------------*
  515. *    Preload carry for cascading adder        *
  516. *-------------------------------------------------------*
  517.     move.w        d4,d1                ; store v[i]
  518.     add.l        d3,d4                ; v[i:f]=v[i:f]+dv[i:f]
  519.     move.w        d1,d4                ; restore v[i]
  520. *-------------------------------------------------------*
  521. *    Execute instruction tower            *
  522. *-------------------------------------------------------*
  523.     clr.l        d1
  524.     jmp        .dx_j(pc,d0.w*8)        ; jump -> index * -16
  525. .dx_l:    vrun16
  526.     vrun16
  527.     vrun16
  528.     vrun16
  529. .dx_j:    dbra        d2,.dx_l
  530. *-------------------------------------------------------*
  531.     dspwaitread
  532.     move.w        (a1),d3                ; i (screen)
  533.     bpl        .next
  534. *-------------------------------------------------------*
  535. .dsp_done:
  536. *-------------------------------------------------------*
  537.     rts
  538.  
  539. *-------------------------------------------------------*
  540. render_wall_2x1:
  541. *-------------------------------------------------------*
  542.     move.l        screen,a4
  543.     move.w        scrwidth,a6
  544.     subq.l        #1,a6
  545.     add.l        a6,a6
  546.     sub.l        a6,a4
  547.     move.w        #128-1,d5
  548.     lea        wall_texture,a3
  549. *-------------------------------------------------------*
  550.     dspwaitread
  551.     move.w        (a1),d3                ; i (screen)
  552.     bmi        .dsp_done
  553. *-------------------------------------------------------*
  554. .next:    moveq        #0,d1
  555.     dspwaitread
  556.     move.w        (a1),d1                ; j1j2
  557. .smod:    lea        colourtables,a5
  558.     lea        (a4,d3.w*4),a0            ; address screen (i)
  559.     moveq        #0,d2
  560.     move.b        d1,d2                ; j2 (screen/bot)
  561.     lsr.w        #8,d1                ; j1 (screen/top)
  562.     sub.w        d1,d2                ; dj (height)
  563.     lsl.l        #4,d1
  564.     move.l        d1,d0
  565.     dspwaitread
  566.     move.w        (a1),d4                ; z
  567.     lea        (a5,d4.w*8),a5            ; address luminance table
  568.     dspwaitread
  569.     move.w        (a1),d4                ; u (texture)
  570.     lsl.l        #2,d1
  571.     add.l        d1,d0
  572.     lsl.l        #3,d0
  573.     dspwaitread
  574.     move.l        -2(a1),d3            ; dv[i:f] (texture)
  575.     add.l        d0,a0                ; address j (screen)
  576.     moveq        #0,d0
  577.     lea        (a3,d4.w),a2            ; address u (texture)
  578.     moveq        #0,d4
  579.     dspwaitread
  580.     move.w        (a1),d4                ; v (texture)
  581.     swap        d3
  582.     ext.w        d3
  583.     lsl.l        #8,d4
  584.     swap        d4
  585. *-------------------------------------------------------*
  586. *    Calculate tower index & interations        *
  587. *-------------------------------------------------------*
  588.     moveq        #4-1,d0
  589.     and.w        d2,d0                ; index = remainder(4)
  590.     lsr.w        #2,d2                ; loopsize / 4
  591.     move.w        d0,d1
  592.     lsl.w        #3,d1
  593.     add.w        d1,d0
  594.     neg.w        d0                ; index * -9
  595. *-------------------------------------------------------*
  596. *    Preload carry for cascading adder        *
  597. *-------------------------------------------------------*
  598.     move.w        d4,d1                ; store v[i]
  599.     add.l        d3,d4                ; v[i:f]=v[i:f]+dv[i:f]
  600.     move.w        d1,d4                ; restore v[i]
  601. *-------------------------------------------------------*
  602. *    Execute instruction tower            *
  603. *-------------------------------------------------------*
  604.     clr.l        d1
  605.     jmp        .dx_j(pc,d0.w*2)        ; jump -> index * -16
  606. .dx_l:    vrun32
  607.     vrun32
  608.     vrun32
  609.     vrun32
  610. .dx_j:    dbra        d2,.dx_l
  611. *-------------------------------------------------------*
  612.     dspwaitread
  613.     move.w        (a1),d3                ; i (screen)
  614.     bpl        .next
  615. *-------------------------------------------------------*
  616. .dsp_done:
  617. *-------------------------------------------------------*
  618.     rts
  619.  
  620.  
  621. *-------------------------------------------------------*
  622. *    Draw composite texture to the screen        *
  623. *-------------------------------------------------------*
  624. render_texture:
  625. *-------------------------------------------------------*
  626.     bsr        clear_patchtags
  627.     bsr        load_patches
  628.     bsr        add_patches
  629.     rts
  630.     
  631. *-------------------------------------------------------*
  632. *    Load all unique patches into temp buffer    *
  633. *-------------------------------------------------------*
  634. load_patches:
  635. *-------------------------------------------------------*
  636.     pushall
  637.     move.l        texturelist_array,a0
  638.     move.l        (a0,d0.w*4),a0
  639.     bsr        open_wad
  640.     move.w        tex_width(a0),patch_xclip
  641.     move.w        tex_height(a0),patch_yclip
  642.     move.w        tex_patches(a0),d6
  643.     lea        tex_len(a0),a0
  644.     bra.s        .go
  645. .all:    move.w        texp_index(a0),d0
  646.     lea        patch_taglist,a1
  647.     move.w        patch_tags,d1
  648.     bra.s        .tgo
  649. .tlp:    cmp.w        (a1),d0
  650.     beq.s        .old
  651.     addq.l        #6,a1
  652. .tgo:    dbra        d1,.tlp
  653.     addq.w        #1,patch_tags
  654.     move.w        d0,(a1)+
  655.     move.l        patchbuffer_ptr,(a1)+
  656.     pushall
  657.     move.l        pnamelist_array,a2
  658.     move.l        (a2,d0.w*4),d1
  659.     beq        .skip
  660.     move.l        d1,a0
  661.     move.l        patchbuffer_ptr,a1
  662.     move.l        wd_size(a0),d1
  663.     add.l        d1,patchbuffer_ptr
  664.     bsr        read_resource
  665. .skip:    popall
  666. .old:    lea        texp_len(a0),a0
  667. .go:    dbra        d6,.all
  668.     bsr        close_wad
  669.     popall
  670.     rts
  671.  
  672. *-------------------------------------------------------*
  673. *    Prepare to load unique patches using tags    *
  674. *-------------------------------------------------------*
  675. clear_patchtags:
  676. *-------------------------------------------------------*
  677.     clr.w        patch_tags
  678.     move.l        #buffer_space,patchbuffer_ptr
  679.     move.w        #max_patches,d1
  680.     lea        patch_taglist,a1
  681.     bra.s        .fgo
  682. .flp:    move.w        #terminator,(a1)+
  683.     addq.l        #4,a1
  684. .fgo:    dbra        d1,.flp
  685.     rts
  686.     
  687. *-------------------------------------------------------*
  688. *    Build texture up from patches            *
  689. *-------------------------------------------------------*
  690. add_patches:
  691. *-------------------------------------------------------*
  692.     pushall
  693.     move.l        texturelist_array,a0
  694.     move.l        (a0,d0.w*4),a0
  695.     move.w        tex_width(a0),patch_xclip
  696.     move.w        tex_height(a0),patch_yclip
  697.     move.w        tex_patches(a0),d6
  698.     lea        tex_len(a0),a0
  699.     bra.s        .go
  700. .all:    move.w        texp_xoff(a0),patch_xoff
  701.     move.w        texp_yoff(a0),patch_yoff
  702.     move.w        texp_index(a0),patch_index
  703.     push.w        d6
  704.     push.l        a0
  705.     bsr        render_patch
  706.     pop.l        a0
  707.     pop.w        d6
  708.     lea        texp_len(a0),a0
  709. .go:    dbra        d6,.all
  710.     popall
  711.     rts
  712.  
  713. *-------------------------------------------------------*
  714. *    Draw one patch as a section of a texture    *
  715. *-------------------------------------------------------*
  716. render_patch:
  717. *-------------------------------------------------------*
  718.     move.w        patch_index,d0
  719.     move.w        patch_tags,d1
  720.     lea        patch_taglist,a1
  721.     bra.s        .fgo
  722. .flp:    cmp.w        (a1),d0
  723.     beq.s        .got
  724.     addq.l        #6,a1
  725. .fgo:    dbra        d1,.flp
  726.     bra        .err
  727. .got:    addq.l        #2,a1
  728.     move.l        (a1)+,a0
  729.     move.l        ScreenPhy,a3
  730.     lea        colourtables+(63*512),a5
  731.     move.l        a0,a1
  732.     imov.w        (a0)+,d6            ; width
  733.     imov.w        (a0)+,d7            ; height
  734.     imov.w        (a0)+,d0            ; xoff
  735.     imov.w        (a0)+,d1            ; yoff
  736.     move.w        patch_yclip,d5
  737.     move.w        patch_yoff,d1
  738.     move.w        patch_xoff,d0
  739.     bpl.s        .xok
  740.     add.w        d0,d6
  741.     ble        .err
  742.     neg.w        d0
  743.     lea        (a0,d0.w*4),a0
  744.     moveq        #0,d0
  745. .xok:    lea        (a3,d0.w*2),a3
  746.     add.w        d6,d0
  747.     sub.w        patch_xclip,d0
  748.     ble.s        .go
  749.     sub.w        d0,d6
  750.     ble        .err
  751.     bra.s        .go
  752. .col:    imov.l        (a0)+,a2
  753.     add.l        a1,a2                ; post data
  754. .next:    moveq        #0,d0
  755.     move.b        (a2)+,d0
  756.     cmp.b        #255,d0
  757.     beq.s        .stop
  758.     move.w        d1,d2                ; base y-offset
  759.     add.w        d0,d2                ; post y-offset
  760.     move.w        d2,d3
  761.     muls.w        #(max_xres*2),d3
  762.     lea        (a3,d3.l),a4
  763.     moveq        #0,d0
  764.     move.b        (a2)+,d0            ; post length
  765.     moveq        #0,d3
  766.     addq.l        #1,a2
  767.     bra.s        .vgo
  768. .vert:    move.b        (a2)+,d3
  769.     tst.w        d2
  770.     bmi.s        .skip
  771.     cmp.w        d5,d2
  772.     bpl.s        .skip
  773.     move.w        (a5,d3.w*2),(a4)
  774. .skip:    addq.w        #1,d2
  775.     lea        (max_xres*2)(a4),a4
  776. .vgo:    dbra        d0,.vert
  777.     addq.l        #1,a2
  778.     bra.s        .next
  779. .stop:    addq.l        #2,a3
  780. .go:    dbra        d6,.col
  781. .err:    rts
  782.     
  783. *-------------------------------------------------------*
  784.             datlong
  785. *-------------------------------------------------------*
  786.  
  787. wall_texture_file:    incbin    data\wall8bit.apx
  788. wall_texture:    =    wall_texture_file+20+768
  789.  
  790. *-------------------------------------------------------*
  791.             bsslong
  792. *-------------------------------------------------------*
  793.  
  794. patchbuffer_ptr:    ds.l    1
  795.  
  796. colourtables:        ds.w    256*64            ; space for 64 light levels of palette
  797.  
  798. patch_xclip:        ds.w    1            ; patch dimensions & clipping rectangle
  799. patch_yclip:        ds.w    1
  800. patch_xoff:        ds.w    1
  801. patch_yoff:        ds.w    1
  802. patch_index:        ds.w    1
  803. patch_tags:        ds.w    1
  804.  
  805. patch_taglist:        ds.b    (2+4)*max_patches    ; space for list of unique patch tags
  806. buffer_space:        ds.b    65536            ; space for all patches in texture
  807.  
  808. final_flat:        ds.b    1            ; flag for last texture run
  809.  
  810. *-------------------------------------------------------*
  811.             txtlong
  812. *-------------------------------------------------------*
  813.